package com.cqs.learning.understanding.the.jvm;

import com.cqs.learning.Demo;
import sun.misc.Launcher;

/**
 *  类加载器的理解
 *
 *
 * @author lixiaowen
 * @create 2019-09-13
 */
public class ClassLoader01 {


    public static void main(String[] args) {
        //Demo.class是应用程序类
        System.out.println(Demo.class.getClassLoader());
        //Integrity在rt.jar中
        System.out.println(Integer.class.getClassLoader());
        //Launcher在Resources.jar中
        System.out.println(Launcher.class.getClassLoader());

        printClassLoaderLink(ClassLoader01.class);
    }


    public static void printClassLoaderLink(Class cls){
        ClassLoader classLoader = cls.getClassLoader();
        while (classLoader != null) {
            System.out.print(classLoader.getClass() + " -> ");
            classLoader = classLoader.getParent() ;
        }
        System.out.println("null");
    }
}
